define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'advertising_roi/index' + location.search,
                    add_url: 'advertising_roi/add',
                    edit_url: 'advertising_roi/edit',
                    del_url: 'advertising_roi/del',
                    multi_url: 'advertising_roi/multi',
                    import_url: 'advertising_roi/import',
                    table: 'advertising_roi',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'createtime',
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        //{field: 'id', title: __('Id')},
                        {field: 'createtime', title: __('日期'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, datetimeFormat:"YYYY-MM-DD"},
                        {field: 'admin_id', title: __('Admin_id'),visible: false,addClass: "selectpage", extend: "data-source='auth/admin/index' data-field='nickname'"},
                        {field: 'admin_name', title: __('Admin_id'), operate: false},
                        {field: 'daily_sales', title: __('Daily_sales'), operate: 'LIKE'},
                        {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                        {field: 'logistics_costs', title: __('Logistics_costs'),editable: {
                            type: 'text',
                            placeholder:"请输入总成本",
                            emptytext : '0'
                        }, operate: 'LIKE'},
                        {field: 'gross_profit', title: __('Gross_profit'), operate: 'LIKE'},
                        {field: 'ordershopifycount', title: __('单量'), operate: false},
                        {field: 'roi', title: __('单转'), operate: false},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});